package com.chen.controller;

import com.chen.base.PageResponse;
import com.chen.base.ResponseResult;
import com.chen.dto.AlertRuleDto;
import com.chen.service.AlertRuleService;
import com.chen.vo.AlertRuleVo;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/alert-rule")
public class AlertRuleController {

    @Resource
    private AlertRuleService alertRuleService;

    @PostMapping("/create")

    public ResponseResult createAlertRule(@RequestBody AlertRuleDto alertRuleDto) {
        alertRuleService.createAlertRule(alertRuleDto);
        return ResponseResult.success();
    }

    @GetMapping("/read/{id}")

    public ResponseResult<AlertRuleVo> readAlertRule(@PathVariable Long id) {
        return ResponseResult.success(alertRuleService.readAlertRule(id));
    }

    @PutMapping("/update/{id}")

    public ResponseResult updateAlertRule(@PathVariable Long id, @RequestBody AlertRuleDto alertRuleDto) {
        alertRuleService.updateAlertRule(id, alertRuleDto);
        return ResponseResult.success();
    }

    @DeleteMapping("/delete/{id}")

    public ResponseResult deleteAlertRule(@PathVariable Long id) {
        alertRuleService.deleteAlertRule(id);
        return ResponseResult.success();
    }

    @GetMapping("/get-page")

    public ResponseResult<PageResponse<AlertRuleVo>> getAlertRulePage(@RequestParam("pageNum") Integer pageNum,
                                                                      @RequestParam("pageSize") Integer pageSize,
                                                                      @RequestParam(value = "alertRuleName", required = false) String alertRuleName,
                                                                      @RequestParam(value = "productKey", required = false) String productKey,
                                                                      @RequestParam(value = "functionName", required = false) String functionName) {
        return ResponseResult.success(alertRuleService.getAlertRulePage(pageNum, pageSize, alertRuleName, productKey, functionName));
    }


    @PutMapping("/{id}/status/{status}")
    public ResponseResult enableOrDisable(@PathVariable Long id, @PathVariable Integer status) {
        alertRuleService.enableOrDisable(id, status);
        return ResponseResult.success();
    }
}